package com.usian.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.usian.common.dtos.PageResult;
import com.usian.common.dtos.ResponseResult;
import com.usian.model.media.dtos.WmMaterialDto;
import com.usian.wemedia.entity.WmMaterial;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import javafx.geometry.Pos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usian.wemedia.service.IWmMaterialService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 自媒体图文素材信息表 前端控制器
 * </p>
 *
 * @author usian
 * @since 2022-07-07
 */
@RestController
@RequestMapping("/api/v1/material")
@Api(tags = "自媒体图文素材信息表接口")
@CrossOrigin
public class WmMaterialController{

    @Autowired
    private IWmMaterialService wmMaterialService;

    @PostMapping("/upload_picture")
    public ResponseResult<String> uploadPic(@RequestParam(name = "multipartFile")MultipartFile file){
       String url = wmMaterialService.uploadPic(file);
        return ResponseResult.ok(url);
    }


    @PostMapping("list")
    public PageResult<WmMaterial> findByPage(@RequestBody WmMaterialDto dto){
        PageResult<WmMaterial> result = wmMaterialService.findByPage(dto);
        return result;
    }


    /**
     * 收藏
     * @param id
     * @return
     */
    @PutMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable(name = "id")Integer id) {
        wmMaterialService.updateCollect(id,true);
        return ResponseResult.ok();
    }

    /**
     * 取消收藏
     * @param id
     * @return
     */
    @PutMapping("/cancel_collect/{id}")
    public ResponseResult collectCancel(@PathVariable(name = "id")Integer id) {
        wmMaterialService.updateCollect(id,false);
        return ResponseResult.ok();
    }

    @DeleteMapping("/del_picture/{id}")
    public ResponseResult delPicture(@PathVariable(name="id") Integer id){
        wmMaterialService.delPicture(id);
        return ResponseResult.ok();
    }
}
